class ASYWindowController < NSObject

  kvc_accessor :downloads
  attr_accessor :downloads

  ib_outlet :txtUrl
  ib_outlet :arrayController

  def init
    if super_init
      @downloads = NSMutableArray.array
      return self
    end
  end

  def getMovie(sender)
  
    pid = @txtUrl.stringValue.to_s
    
    if pid =~ %r!/item/([a-z0-9]{8})!
      pid = $1
    end
    
    if pid == ""
      # return
      pid = "b00b563l" # Dr Who for now :)
    end

    # TODO: handle HTTP proxy settings
    #if http_proxy = OPTIONS[:http_proxy]
    #  http_proxy = 'http://' + http_proxy unless http_proxy =~ %r{^http://}
    #  u = URI.parse(http_proxy)
    #  http = Net::HTTP::Proxy(u.host, u.port)
    #else
    #  http = Net::HTTP
    #end
    
    NSLog("Downloading PID #{pid}")
    d = IPlayerDownload.new
    @arrayController.addObject(d)
    d.start_download(pid)

  end
  
  ib_action :getMovie
   
end
